﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Wp7Tools.Converters {
    public class DateTimeConverter : IValueConverter {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            if (parameter == null) {
                parameter = "d";
            }
            DateTime dateTime = (DateTime) value;
            string formatedDate = dateTime.ToString(parameter.ToString(), culture);
            return char.ToUpper(formatedDate[0]) + formatedDate.Substring(1);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            if (parameter == null) {
                parameter = "d";
            }
            return DateTime.ParseExact(value.ToString(), parameter.ToString(), culture);
        }
    }
}